package com.omesoft.hksnore.util.photo;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.widget.LinearLayout.LayoutParams;

/***
 * ����ת����
 * 
 * @author Administrator
 * 
 */
public class MyPixelConvertUtil {
	private static DisplayMetrics dm = new DisplayMetrics();
	public final static int Pixe240X320=0;
	public final static int Pixe320X480=1;
	public final static int Pixe480X800=2;
	public final static int Pixe480X854=3;
	
	private static int defaultTextSize;
	/**�����ж���һ���ֻ���ʾ����*/
	public static int showStyle;
	public static int width, height;
	public static int dip2px(Context context, float dipValue) {
		final float density = context.getResources().getDisplayMetrics().density;
//	    Log.v("test","density:"+density);
		return (int)(dipValue * (density ));
	}

	public static int px2dip(Context context, float pxValue) {
		final float density = context.getResources().getDisplayMetrics().density;
		Log.v("test","density:"+density);
		return (int) (pxValue / ((density )));
	}
	
	public static int px2sp(Context context, float pxValue) {
		final float density = context.getResources().getDisplayMetrics().scaledDensity;
		Log.v("test","density:"+density);
		return (int) (pxValue / ((density ))+0.5f);
	}
	
	public static int sp2px(Context context, float spValue) {
		final float density = context.getResources().getDisplayMetrics().scaledDensity;
//	    Log.v("test","density:"+density);
		return (int)(spValue * (density )+0.5f);
	}

	/** ȫ�ֵ������С����width=480Ϊ׼ */
	public static int getConvertSize(Activity activity, int size) {
		if (activity != null) {

			WindowManager manager = activity.getWindowManager();
			Display display = manager.getDefaultDisplay();
			display.getMetrics(dm);
			int width, height;
			width = dm.widthPixels;
			height = dm.heightPixels;
			if (width == 480 && height > 800) {
				defaultTextSize = MyPixelConvertUtil.dip2px(activity, size);
			} else if (width == 480 && height > 480 && height <= 800) {
				defaultTextSize = MyPixelConvertUtil.dip2px(activity, size);
			} else if (width == 320 && height > 320 && height <= 480) {
				defaultTextSize = MyPixelConvertUtil.dip2px(activity, size);
			} else if (width == 240 && height <= 320) {
				defaultTextSize = MyPixelConvertUtil.dip2px(activity, size);
			}
		}
		return defaultTextSize;
	}
	/**������һ�ֱַ���*/
	public static int getShowStyle(Activity activity) {
		if (activity != null) {
			WindowManager manager = activity.getWindowManager();
			Display display = manager.getDefaultDisplay();
			display.getMetrics(dm);
			
			width = dm.widthPixels;
			height = dm.heightPixels;
			if (width >= 480 && height > 800) {
				showStyle =Pixe480X854;
			} else if (width > 320 &&width <= 480 && height > 480 && height <= 800) {
				showStyle  =Pixe480X800;
			} else if (width > 240 &&width <= 320 && height > 320 && height <= 480) {
				showStyle = Pixe320X480;
			} else if (width <= 240 && height <= 320) {
				showStyle = Pixe240X320;
			}
		}
		return showStyle;
	}
	
	/**��Ļ���*/
	public static int getScreenWidth(Activity activity) {
		WindowManager manager = activity.getWindowManager();
		Display display = manager.getDefaultDisplay();
		display.getMetrics(dm);

		return dm.widthPixels;
	}
	
	/**��Ļ�߶�*/
	public static float getScreenHeight(Activity activity) {
		WindowManager manager = activity.getWindowManager();
		Display display = manager.getDefaultDisplay();
		display.getMetrics(dm);
		return dm.heightPixels;
	}
	/**��ȡ�����߶�*/
	public static int getFootBarHeight(Activity activity) {
		int footBarHeight = 0;
		switch (getShowStyle(activity)) {
		case 0:
			footBarHeight =32;
			break;
		case 1:
			footBarHeight =50;
			break;
		case 2:
			footBarHeight =80;
			break;
		case 3:
			footBarHeight =80;
			break;
		}
		return footBarHeight;
	}
	
	/**��ȡ״̬���ӱ������ĸ߶�*/
	public static int getStatusBarHeight(Activity activity) {
		int footBarHeight = 0;
		switch (getShowStyle(activity)) {
		case 0:
			footBarHeight =21;
			break;
		case 1:
			footBarHeight =28;
			break;
		case 2:
			footBarHeight =35;
			break;
		case 3:
			footBarHeight =40;
			break;
		}
		return footBarHeight;
	}
	/** ���ý�����Y���� */
	public static int getProgressBarLocation(Activity activity) {
		getShowStyle(activity);
		int footBarHeight = height * 2 / 3;

		return footBarHeight;
	}
	/**����ָ�����*/
	public static LayoutParams getLayoutParamsByWidthDip(Context context,int widthDip) {
		return new LayoutParams(MyPixelConvertUtil.dip2px(context, widthDip), LayoutParams.FILL_PARENT);
	}
	
	/**����ָ�����*/
	public static LayoutParams getLayoutParams_w_f() {
		return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
	}
	
	/**���ø߶ȺͿ�ȶ��������*/
	public static LayoutParams getLayoutParams_f_f() {
		return new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
	}
	
	/**���ø߶ȺͿ�ȶ���������*/
	public static LayoutParams getLayoutParams_w_w() {
		return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	}
}
